//
//  ZCMeAuditDetailsVC.m
//  zctx
//
//  Created by apple on 15/10/14.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCMeAuditDetailsVC.h"
#import "ZCprojectdetailinfoCell.h"


@interface ZCMeAuditDetailsVC ()<UITableViewDataSource,UITableViewDelegate>{
    NSMutableDictionary *datadictionary;

}
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UILabel *titlenameLable;
@end

@implementation ZCMeAuditDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"项目详情"];
    [self requestProjectdetailsdata];
    [self initTableView];
    [self initTableViewHeaderView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCprojectdetailinfoCell" bundle:nil] forCellReuseIdentifier:@"info"];
}

#pragma mark 导航栏
-(void)initnavegation{
    
    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 19, 36);
    [leftButton setImage:[UIImage imageNamed:@"navigation_back"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barButtonItem_leftNavBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = barButtonItem_leftNavBar;
}

-(void)backButtonPressed{
    ProgressDismiss;
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 请求项目详情数据
-(void)requestProjectdetailsdata{
    ProgressHUDStr;
    [NetworkManager requestFoundingGetOneWithId:self.pid Mid:UserModel.mid password:UserModel.password success:^(NSDictionary *dictResponse) {
        ProgressDismiss;
        datadictionary = [dictResponse mutableCopy];
//        self.titlenameLable.text = [NSString stringWithFormat:@"%@",[datadictionary objectForKey:@"pjname"]];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        ProgressDismiss;
        [self.tableView removeFromSuperview];
    }];
}

#pragma mark TableViewHeaderView

-(void)initTableViewHeaderView{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,44)];
    headView.backgroundColor = [UIColor whiteColor];
    
    self.titlenameLable = [UILabel new];
    [headView addSubview:self.titlenameLable];
    [self.titlenameLable setText:self.titlteStr];
    self.titlenameLable.font = [UIFont systemFontOfSize:16];
    self.titlenameLable.textAlignment = NSTextAlignmentCenter;
    [self.titlenameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(headView.mas_centerX);
        make.centerY.equalTo(headView.mas_centerY);
        make.width.mas_equalTo(@(SCREEN_WIDTH));
        make.height.mas_equalTo(@(30));
    }];
    self.tableView.tableHeaderView = headView;
}

-(void)initTableView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.delegate =self;
    self.tableView.dataSource = self;
    self.tableView.sectionFooterHeight =0.0001;
    [self.view addSubview:self.tableView];
    [self.tableView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0,0,0));
        }];
}

#pragma mark UITableViewDataSource,UITableViewDelegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if([datadictionary count]>0){
        return 2;
    }else{
        return 0;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if(section==0){
        return 1;
    }else{
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZCProjectdetailsModel *detailsmodel = [ZCProjectdetailsModel modelObjectWithDictionary:datadictionary];

    ZCprojectdetailinfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"info"];
    cell.detailesModel = detailsmodel;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 148;
    }else{
        return 0;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
 
    return 40;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   
    NSArray *titleArray = [NSArray arrayWithObjects:@"基本信息",@"项目进度",nil];
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    headView.backgroundColor = [UIColor whiteColor];
    UIView *bgheadView = [UIView new];
    [headView addSubview:bgheadView];
    bgheadView.backgroundColor = [UIColor colorWithHexString:@"#ebeded"];
    [bgheadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headView.top).with.offset(0);
        make.left.equalTo(headView).with.offset(0);
        make.right.equalTo(headView).with.offset(0);
        make.height.mas_equalTo(@10);
    }];
    
    UIView *newView = [UIView new];
    [headView addSubview:newView];
    [newView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headView.top).with.offset(10);
        make.left.equalTo(headView).with.offset(0);
        make.right.equalTo(headView).with.offset(0);
        make.bottom.equalTo(headView).with.offset(0);
    }];
    
    UILabel *leftlable = [UILabel new];
    [newView addSubview:leftlable];
    leftlable.font = [UIFont systemFontOfSize:16];
    [leftlable setText:titleArray[section]];
    //        [leftlable setText:@"最新检测结果"];
    [leftlable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(newView.mas_centerY);
        make.left.equalTo(newView).with.offset(15);
        make.height.mas_equalTo(@30);
        make.width.mas_equalTo(@150);
    }];
    
    if (section==1) {
        UILabel *statelable = [UILabel new];
        [newView addSubview:statelable];
        statelable.font = [UIFont systemFontOfSize:16];
        statelable.textColor = MainColor;
        [statelable setText:@"审核中"];
        [statelable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(newView.mas_centerY);
            make.right.equalTo(newView).with.offset(-15);
            make.height.mas_equalTo(@30);
            //            make.width.mas_equalTo(@150);
        }];
        
    }
    return headView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
